﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SuperSocket.SocketBase.Command;
using SuperSocket.SocketBase.Protocol;
using VswService_V7.ClientCommand;

namespace VswService_V7.Sok.Command
{
	public class Defined : CommandBase<VswSession, StringRequestInfo>
	{
		public override void ExecuteCommand(VswSession session, StringRequestInfo requestInfo)
		{
			//Defined command format： key；command id; time;p1-pn
			if (requestInfo.Parameters.Length >= 2)
			{
				CommandContent content = new CommandContent(session, requestInfo.Parameters);
				ClientMessageHandler.MessageHandler.Add(content);
			}

			else
			{
				session.Send("CONTENTERROR##");
			}


			//防止某个连接恶意高频操作
			//TimeSpan timeSpanBegin = new TimeSpan(session.LastActiveTime.Ticks);
			//TimeSpan timeSpanEnd = new TimeSpan(DateTime.Now.Ticks);
			//double timeSpanDuring = timeSpanEnd.Subtract(timeSpanBegin).TotalMilliseconds;
			//if (timeSpanDuring > 10)
			//{
			//    //Defined 命令格式： key；command id; time;p1-pn
			//    if (requestInfo.Parameters.Length >= 2)
			//    {
			//        CommandContent content = new CommandContent(session, requestInfo.Parameters);
			//        ClientMessageHandler.MessageHandler.Add(content);
			//    }

			//    else
			//    {
			//        session.Send("CONTENT_ERROR##");
			//    }
			//}
			//else
			//{
			//    session.Send(requestInfo.Parameters[0] + ";Operation busy!##");
			//}

		}
	}		
}
